Framework

A custom tool class based on the Base GMOD Toolgun, designed for integration with Lilia's framework.

The ToolGun class extends the functionality of the base GMOD toolgun, enabling seamless integration with Lilia's files and configuration. This custom tool class provides a flexible framework for creating and managing interactive tools within Garry's Mod, specifically tailored to work with Lilia's environment and system.

The ToolGun class is designed to work in conjunction with Lilia's file system and configuration setup. It allows for the implementation of toolguns that can be dynamically loaded and configured based on Lilia's files, offering a robust solution for extending tool functionalities in a modular way.

Customization and Flexibility:

The ToolGun class provides a foundation for creating custom tools that integrate smoothly with Lilia's system. Developers can extend and modify the class to fit specific needs, leveraging Lilia's configuration files to dictate tool behavior and appearance. This approach ensures that tools can be easily adapted and updated in line with Lilia's framework, providing a consistent and maintainable tool environment.

By integrating with Lilia's files, the ToolGun class enables developers to build sophisticated tools that are fully compatible with Lilia's system, enhancing the overall gameplay experience and tool management within Garry's Mod.

Functions

ToolGunMeta:Allowed()

Checks if the tool is allowed on the server. This method returns whether the tool is allowed based on the server convar AllowedCVar. It always returns true on the client-side.

Returns

  • Boolean

    True if the tool is allowed, false otherwise.

Example Usage

if tool:Allowed() then
    print("Tool is allowed.")
else
    print("Tool is not allowed.")
end

ToolGunMeta:BuildConVarList()

Builds a list of client-side convars. This method constructs a table of convars by appending the mode prefix to each convar name.

Returns

  • Table

    A table containing the mode-prefixed convars.

Example Usage

local convars = tool:BuildConVarList()
for k, v in pairs(convars) do
    print(k, v)
end

ToolGunMeta:CheckObjects()

Checks the validity of objects the tool is manipulating. This method iterates over the tool's objects and clears them if they are no longer valid, such as if the entity is no longer part of the world or is invalid.

Example Usage

tool:CheckObjects()

ToolGunMeta:ClearObjects()

Clears all objects the tool is manipulating. This method removes all objects from the tool's Objects table, effectively resetting the tool's state.

Example Usage

tool:ClearObjects()

ToolGunMeta:Create()

Creates a new tool object. This method initializes a new tool object with default properties. It sets up the metatable and various default values such as Mode, SWEP, Owner, ClientConVar, ServerConVar, Objects, Stage, Message, LastMessage, and AllowedCVar.

Returns

  • Table

    A new tool object with default properties.

Example Usage

local tool = ToolGunMeta:Create()
tool.Mode = "builder"

ToolGunMeta:CreateConVars()

Creates client and server convars for the tool. This method generates convars (console variables) based on the tool's mode. Client convars are created on the client-side, while server convars are created on the server-side.

Example Usage

tool:CreateConVars()

ToolGunMeta:CustomLogic()

Placeholder for handling tool-specific logic. This method is intended to be overridden to implement custom logic that should be executed periodically or under specific conditions.

Example Usage

function ToolGunMeta:CustomLogic()
    -- Custom periodic logic here
end

ToolGunMeta:Deploy()

Deploys the tool. This method is called when the player equips the tool. It releases any ghost entities associated with the tool.

Example Usage

function ToolGunMeta:Deploy()
    self:ReleaseGhostEntity()
end

ToolGunMeta:GetClientInfo(property)

Retrieves client-side information for a given property. This method returns the value of a client-side convar associated with the tool's mode.

Parameters

  • property String

    The name of the property to retrieve.

Returns

  • String

    The value of the client convar.

Example Usage

local toolSetting = tool:GetClientInfo("setting")
print("Tool Setting:", toolSetting)

ToolGunMeta:GetClientNumber(property, default)

Retrieves a numerical value from client-side convars. This method returns the value of a client-side convar as a number, or a default value if the convar does not exist.

Parameters

  • property String

    The name of the property to retrieve.

  • default Float

    The default value to return if the convar does not exist.

Returns

  • Float

    The numerical value of the client convar.

Example Usage

local toolPower = tool:GetClientNumber("power", 10)
print("Tool Power:", toolPower)

ToolGunMeta:GetMode()

Retrieves the mode of the tool. This method returns the current mode of the tool, which is a string representing the specific operation the tool is set to perform.

Returns

  • String

    The current mode of the tool.

Example Usage

local mode = tool:GetMode()
print("Tool Mode:", mode)

ToolGunMeta:GetOwner()

Retrieves the owner of the tool. This method returns the player who owns the tool by accessing the SWEP's Owner property.

Returns

  • Player

    The player who owns the tool.

Example Usage

local owner = tool:GetOwner()
print("Tool Owner:", owner:Nick())

ToolGunMeta:GetSWEP()

Retrieves the SWEP (Scripted Weapon) associated with the tool. This method returns the SWEP object, which is typically the weapon the player is holding while using the tool.

Returns

  • SWEP

    The SWEP object associated with the tool.

Example Usage

local swep = tool:GetSWEP()
print("Tool SWEP:", swep:GetClass())

ToolGunMeta:GetServerInfo(property)

Retrieves server-side information for a given property. This method returns the value of a server-side convar associated with the tool's mode.

Parameters

  • property String

    The name of the property to retrieve.

Returns

  • ConVar

    The server convar object.

Example Usage

local allowUse = tool:GetServerInfo("allow_use"):GetBool()

ToolGunMeta:GetWeapon()

Retrieves the weapon associated with the tool. This method returns the weapon associated with the tool by accessing the SWEP's Weapon property or the tool's own Weapon property.

Returns

  • Weapon

    The weapon object associated with the tool.

Example Usage

local weapon = tool:GetWeapon()
print("Associated Weapon:", weapon:GetClass())

ToolGunMeta:Holster()

Holsters the tool. This method is called when the player unequips the tool. It releases any ghost entities associated with the tool.

Example Usage

function ToolGunMeta:Holster()
    self:ReleaseGhostEntity()
end

ToolGunMeta:Init()

Placeholder for initializing the tool. This method is intended to be overridden if initialization logic is needed when the tool is created.

Example Usage

function ToolGunMeta:Init()
    -- Custom initialization logic here
end

ToolGunMeta:LeftClick()

Handles the left-click action with the tool. This method is intended to be overridden to define what happens when the player left-clicks with the tool. By default, it does nothing and returns false.

Returns

  • Boolean

    False by default, indicating no action was taken.

Example Usage

function ToolGunMeta:LeftClick(trace)
    -- Custom left-click logic here
    return true
end

ToolGunMeta:ReleaseGhostEntity()

Releases any ghost entities associated with the tool. This method removes any ghost entities the tool may be holding, ensuring that no visual artifacts remain when the tool is not actively manipulating objects.

Example Usage

tool:ReleaseGhostEntity()

ToolGunMeta:Reload()

Handles the reload action with the tool. This method clears the objects that the tool is currently manipulating when the player reloads with the tool.

Example Usage

function ToolGunMeta:Reload()
    self:ClearObjects()
end

ToolGunMeta:RightClick()

Handles the right-click action with the tool. This method is intended to be overridden to define what happens when the player right-clicks with the tool. By default, it does nothing and returns false.

Returns

  • Boolean

    False by default, indicating no action was taken.

Example Usage

function ToolGunMeta:RightClick(trace)
    -- Custom right-click logic here
    return true
end

ToolGunMeta:Think()

Handles the tool's "think" logic. This method is called periodically to perform updates. By default, it releases any ghost entities associated with the tool.

Example Usage

function ToolGunMeta:Think()
    self:ReleaseGhostEntity()
end